include(AwsTestHarness)
include(AwsLibFuzzer)
enable_testing()

file(GLOB TEST_HDRS "*.h")
file(GLOB TEST_SRC "*.c")
file(GLOB TESTS ${TEST_HDRS} ${TEST_SRC})

# Adds two test cases, where second one ends with "_one_byte_at_a_time"
macro(add_one_byte_at_a_time_test_set NAME)
    add_test_case("${NAME}")
    add_test_case("${NAME}_one_byte_at_a_time")
endmacro()

# Each h2_decoder test is run multiple ways. This adds each test case.
macro(add_h2_decoder_test_set NAME)
    add_test_case("${NAME}")
    add_test_case("${NAME}_one_byte_at_a_time")
endmacro()

add_test_case(headers_add)
add_test_case(headers_add_array)
add_test_case(headers_set)
add_test_case(headers_erase_index)
add_test_case(headers_erase)
add_test_case(headers_erase_value)
add_test_case(headers_clear)
add_test_case(headers_get_all)
add_test_case(h2_headers_request_pseudos_get_set)
add_test_case(h2_headers_response_pseudos_get_set)

add_test_case(message_sanity_check)
add_test_case(message_request_method)
add_test_case(message_request_path)
add_test_case(message_response_status)
add_test_case(message_refcounts)
add_test_case(message_with_existing_headers)

add_test_case(h1_test_get_request)
add_test_case(h1_test_request_bad_version)
add_test_case(h1_test_response_unsupported_version)
add_test_case(h1_test_response_1_0)
add_test_case(h1_test_get_status_code)
add_test_case(h1_test_overflow_scratch_space)
add_test_case(h1_test_receive_request_headers)
add_test_case(h1_test_receive_response_headers)
add_test_case(h1_test_get_transfer_encoding_flags)
add_test_case(h1_test_body_unchunked)
add_test_case(h1_test_body_chunked)
add_test_case(h1_decode_trailers)
add_test_case(h1_decode_one_byte_at_a_time)
add_test_case(h1_decode_messages_at_random_intervals)
add_test_case(h1_decode_bad_requests_and_assert_failure)
add_test_case(h1_decode_bad_responses_and_assert_failure)
add_test_case(h1_test_extraneous_buffer_data_ensure_not_processed)
add_test_case(h1_test_ignore_chunk_extensions)

add_test_case(h1_encoder_content_length_put_request_headers)
add_test_case(h1_encoder_transfer_encoding_chunked_put_request_headers)
add_test_case(h1_encoder_transfer_encoding_chunked_put_request_multiple_te_headers)
add_test_case(h1_encoder_transfer_encoding_chunked_put_request_headers_case_insensitivity)
add_test_case(h1_encoder_transfer_encoding_chunked_and_content_length_put_request_headers)
add_test_case(h1_encoder_transfer_encoding_not_chunked_put_request_headers)
add_test_case(h1_encoder_transfer_encoding_set_body_stream_errors)
add_test_case(h1_encoder_transfer_encoding_chunked_multiple_put_request_headers)
add_test_case(h1_encoder_transfer_encoding_chunked_not_final_encoding_put_request_headers)
add_test_case(h1_encoder_transfer_encoding_not_ending_in_chunked_put_request_headers)
add_test_case(h1_encoder_rejects_bad_method)
add_test_case(h1_encoder_rejects_missing_method)
add_test_case(h1_encoder_rejects_bad_path)
add_test_case(h1_encoder_rejects_missing_path)
add_test_case(h1_encoder_rejects_bad_header_name)
add_test_case(h1_encoder_rejects_bad_header_value)

add_test_case(h1_client_sanity_check)
add_test_case(h1_client_request_send_1liner)
add_test_case(h1_client_request_send_headers)
add_test_case(h1_client_request_send_body)
add_test_case(h1_client_request_send_body_chunked)
add_test_case(h1_client_request_send_chunked_trailer)
add_test_case(h1_client_request_forbidden_trailer)
add_test_case(h1_client_request_send_empty_chunked_trailer)
add_test_case(h1_client_request_send_large_body)
add_test_case(h1_client_request_send_large_body_chunked)
add_test_case(h1_client_request_send_large_head)
add_test_case(h1_client_request_content_length_0_ok)
add_test_case(h1_client_request_waits_for_chunks)
add_test_case(h1_client_request_send_chunk_from_chunk_complete_callback)
add_test_case(h1_client_request_write_chunk_as_write_completes_regression)
add_test_case(h1_client_request_send_chunked_extensions)
add_test_case(h1_client_request_send_large_chunk_extensions)
add_test_case(h1_client_request_send_chunk_size_0_ok)
add_test_case(h1_client_request_send_chunk_size_0_with_extensions_ok)
add_test_case(h1_client_request_content_length_too_small_is_error)
add_test_case(h1_client_request_content_length_too_large_is_error)
add_test_case(h1_client_request_chunk_size_too_small_is_error)
add_test_case(h1_client_request_chunk_size_too_large_is_error)
add_test_case(h1_client_request_chunks_cancelled_by_channel_shutdown)
add_test_case(h1_client_request_send_multiple)
add_test_case(h1_client_request_send_multiple_chunked_encoding)
add_test_case(h1_client_request_close_header_ends_connection)
add_test_case(h1_client_request_close_header_with_pipelining)
add_test_case(h1_client_request_close_header_with_chunked_encoding_and_pipelining)
add_test_case(h1_client_stream_release_after_complete)
add_test_case(h1_client_stream_release_before_complete)
add_test_case(h1_client_response_get_1liner)
add_test_case(h1_client_response_get_headers)
add_test_case(h1_client_response_get_body)
add_test_case(h1_client_response_get_no_body_for_head_request)
add_test_case(h1_client_response_get_no_body_from_304)
add_test_case(h1_client_response_get_100)
add_test_case(h1_client_response_get_1_from_multiple_io_messages)
add_test_case(h1_client_response_get_multiple_from_1_io_message)
add_test_case(h1_client_response_with_bad_data_shuts_down_connection)
add_test_case(h1_client_response_with_too_much_data_shuts_down_connection)
add_test_case(h1_client_response_arrives_before_request_done_sending_is_ok)
add_test_case(h1_client_response_arrives_before_request_chunks_done_sending_is_ok)
add_test_case(h1_client_response_without_request_shuts_down_connection)
add_test_case(h1_client_response_close_header_ends_connection)
add_test_case(h1_client_response_close_header_with_pipelining)
add_test_case(h1_client_respects_stream_window)
add_test_case(h1_client_connection_window_with_buffer)
add_test_case(h1_client_connection_window_with_small_buffer)
add_test_case(h1_client_request_cancelled_by_channel_shutdown)
add_test_case(h1_client_multiple_requests_cancelled_by_channel_shutdown)
add_test_case(h1_client_new_request_fails_if_channel_shut_down)
add_test_case(h1_client_error_from_outgoing_body_callback_stops_decoder)
add_test_case(h1_client_error_from_incoming_headers_callback_stops_decoder)
add_test_case(h1_client_error_from_incoming_headers_done_callback_stops_decoder)
add_test_case(h1_client_error_from_incoming_body_callback_stops_decoder)
add_test_case(h1_client_close_from_off_thread_makes_not_open)
add_test_case(h1_client_close_from_on_thread_makes_not_open)
add_test_case(h1_client_unactivated_stream_cleans_up)
add_test_case(h1_client_new_request_allowed)
add_test_case(h1_client_midchannel_sanity_check)
add_test_case(h1_client_midchannel_read)
add_test_case(h1_client_midchannel_read_immediately)
add_test_case(h1_client_midchannel_read_with_small_downstream_window)
add_test_case(h1_client_midchannel_write)
add_test_case(h1_client_midchannel_write_continues_after_shutdown_in_read_dir)
add_test_case(h1_client_midchannel_requires_switching_protocols)
add_test_case(h1_client_switching_protocols_fails_pending_requests)
add_test_case(h1_client_switching_protocols_fails_subsequent_requests)
add_test_case(h1_client_switching_protocols_requires_downstream_handler)
add_test_case(h1_client_connection_close_before_request_finishes)
add_test_case(h1_client_response_close_connection_before_request_finishes)

add_test_case(strutil_trim_http_whitespace)
add_test_case(strutil_is_http_token)
add_test_case(strutil_is_lowercase_http_token)
add_test_case(strutil_is_http_field_value)
add_test_case(strutil_is_http_reason_phrase)
add_test_case(strutil_is_http_request_target)
add_test_case(strutil_is_http_pseudo_header_name)

add_net_test_case(tls_download_medium_file_h1)
add_net_test_case(tls_download_medium_file_h2)

add_test_case(websocket_decoder_sanity_check)
add_test_case(websocket_decoder_simplest_frame)
add_test_case(websocket_decoder_rsv)
add_test_case(websocket_decoder_data_frame)
add_test_case(websocket_decoder_stops_at_frame_end)
add_test_case(websocket_decoder_masking)
add_test_case(websocket_decoder_extended_length_2byte)
add_test_case(websocket_decoder_extended_length_8byte)
add_test_case(websocket_decoder_1byte_at_a_time)
add_test_case(websocket_decoder_fail_on_unknown_opcode)
add_test_case(websocket_decoder_fragmented_message)
add_test_case(websocket_decoder_fail_on_bad_fragmentation)
add_test_case(websocket_decoder_control_frame_cannot_be_fragmented)
add_test_case(websocket_decoder_utf8_text)
add_test_case(websocket_decoder_fail_on_bad_utf8_text)
add_test_case(websocket_decoder_fragmented_utf8_text)
add_test_case(websocket_decoder_fail_on_fragmented_bad_utf8_text)
add_test_case(websocket_decoder_on_frame_callback_can_fail_decoder)
add_test_case(websocket_decoder_on_payload_callback_can_fail_decoder)
add_test_case(websocket_encoder_sanity_check)
add_test_case(websocket_encoder_simplest_frame)
add_test_case(websocket_encoder_rsv)
add_test_case(websocket_encoder_data_frame)
add_test_case(websocket_encoder_fail_if_payload_exceeds_stated_length)
add_test_case(websocket_encoder_masking)
add_test_case(websocket_encoder_extended_length)
add_test_case(websocket_encoder_1_byte_at_a_time)
add_test_case(websocket_encoder_fragmented_message)
add_test_case(websocket_encoder_fragmentation_failure_checks)
add_test_case(websocket_encoder_payload_callback_can_fail_encoder)
add_test_case(websocket_handler_sanity_check)
add_test_case(websocket_handler_refcounting)
add_test_case(websocket_handler_send_frame)
add_test_case(websocket_handler_send_frame_off_thread)
add_test_case(websocket_handler_send_multiple_frames)
add_test_case(websocket_handler_send_huge_frame)
add_test_case(websocket_handler_send_payload_slowly)
add_test_case(websocket_handler_send_payload_with_pauses)
add_test_case(websocket_handler_sends_nothing_after_close_frame)
add_test_case(websocket_handler_send_frames_always_complete)
add_test_case(websocket_handler_send_one_io_msg_at_a_time)
add_test_case(websocket_handler_delayed_write_completion)
add_test_case(websocket_handler_send_halts_if_payload_fn_returns_false)
add_test_case(websocket_handler_shutdown_automatically_sends_close_frame)
add_test_case(websocket_handler_shutdown_handles_queued_close_frame)

# add_test_case(websocket_handler_shutdown_immediately_in_emergency) disabled until channel API exposes immediate shutdown
add_test_case(websocket_handler_shutdown_handles_unexpected_write_error)
add_test_case(websocket_handler_close_on_thread)
add_test_case(websocket_handler_close_off_thread)
add_test_case(websocket_handler_read_frame)
add_test_case(websocket_handler_read_multiple_frames)
add_test_case(websocket_handler_read_frames_split_across_io_messages)
add_test_case(websocket_handler_read_frames_complete_on_shutdown)
add_test_case(websocket_handler_read_halts_if_begin_fn_returns_false)
add_test_case(websocket_handler_read_halts_if_payload_fn_returns_false)
add_test_case(websocket_handler_read_halts_if_complete_fn_returns_false)
add_test_case(websocket_handler_window_manual_increment)
add_test_case(websocket_handler_window_manual_increment_off_thread)
add_test_case(websocket_handler_sends_pong_automatically)
add_test_case(websocket_handler_wont_send_pong_after_close_frame)
add_test_case(websocket_midchannel_sanity_check)
add_test_case(websocket_midchannel_write_message)
add_test_case(websocket_midchannel_write_multiple_messages)
add_test_case(websocket_midchannel_write_huge_message)
add_test_case(websocket_midchannel_read_message)
add_test_case(websocket_midchannel_read_multiple_messages)
add_test_case(websocket_boot_sanity_check)
add_test_case(websocket_boot_golden_path)
add_test_case(websocket_boot_fail_at_http_connect)
add_test_case(websocket_boot_fail_at_http_connect_error)
add_test_case(websocket_boot_fail_at_new_request)
add_test_case(websocket_boot_fail_at_activate_request)
add_test_case(websocket_boot_fail_before_response_headers)
add_test_case(websocket_boot_fail_before_response_headers_done)
add_test_case(websocket_boot_fail_at_new_handler)
add_test_case(websocket_boot_report_unexpected_http_shutdown)
add_test_case(websocket_boot_fail_from_handshake_rejection)
add_test_case(websocket_boot_fail_before_handshake_rejection_body)
add_test_case(websocket_boot_fail_before_handshake_rejection_stream_complete)
add_test_case(websocket_boot_fail_from_invalid_upgrade_header)
add_test_case(websocket_boot_fail_from_missing_upgrade_header)
add_test_case(websocket_boot_fail_from_invalid_connection_header)
add_test_case(websocket_boot_fail_from_invalid_sec_websocket_accept_header)
add_test_case(websocket_boot_fail_from_unsupported_sec_websocket_extensions_in_request)
add_test_case(websocket_boot_fail_from_unsupported_sec_websocket_extensions_in_response)
add_test_case(websocket_boot_ok_with_sec_websocket_protocol_header)
add_test_case(websocket_boot_ok_with_sec_websocket_protocol_split_across_headers)
add_test_case(websocket_boot_fail_from_missing_sec_websocket_protocol_header)
add_test_case(websocket_boot_fail_from_invalid_sec_websocket_protocol_header)
add_test_case(websocket_handshake_key_max_length)
add_test_case(websocket_handshake_key_randomness)

add_test_case(hpack_encode_integer)
add_one_byte_at_a_time_test_set(hpack_decode_integer_5bits)
add_one_byte_at_a_time_test_set(hpack_decode_integer_14bits)
add_one_byte_at_a_time_test_set(hpack_decode_integer_8bits)
add_one_byte_at_a_time_test_set(hpack_decode_integer_21bits)
add_one_byte_at_a_time_test_set(hpack_decode_integer_ongoing)
add_one_byte_at_a_time_test_set(hpack_decode_integer_too_big)
add_one_byte_at_a_time_test_set(hpack_decode_integer_few_in_a_row)
add_test_case(hpack_decode_string_blank)
add_one_byte_at_a_time_test_set(hpack_decode_string_uncompressed)
add_one_byte_at_a_time_test_set(hpack_decode_string_huffman)
add_one_byte_at_a_time_test_set(hpack_decode_string_ongoing)
add_one_byte_at_a_time_test_set(hpack_decode_string_short_buffer)
add_test_case(hpack_static_table_find)
add_test_case(hpack_static_table_get)
add_test_case(hpack_dynamic_table_find)
add_test_case(hpack_dynamic_table_get)
add_test_case(hpack_decode_indexed_from_dynamic_table)
add_test_case(hpack_dynamic_table_empty_value)
add_test_case(hpack_dynamic_table_with_empty_header)
add_test_case(hpack_dynamic_table_size_update_from_setting)

if(ENABLE_LOCALHOST_INTEGRATION_TESTS)
    # Tests should be named with localhost_integ_*
    add_net_test_case(localhost_integ_hpack_stress)
    add_net_test_case(localhost_integ_hpack_compression_stress)
    add_net_test_case(localhost_integ_h2_upload_stress)
    add_net_test_case(localhost_integ_h2_download_stress)
endif()

add_test_case(h2_header_empty_payload)
add_one_byte_at_a_time_test_set(h2_header_ex_2_1)
add_one_byte_at_a_time_test_set(h2_header_ex_2_2)
add_one_byte_at_a_time_test_set(h2_header_ex_2_3)
add_one_byte_at_a_time_test_set(h2_header_ex_2_4)
add_one_byte_at_a_time_test_set(h2_header_ex_3)
add_one_byte_at_a_time_test_set(h2_header_ex_4)
add_one_byte_at_a_time_test_set(h2_header_ex_5)
add_one_byte_at_a_time_test_set(h2_header_ex_6)

add_test_case(h2_encoder_data)
add_test_case(h2_encoder_data_stalled)
add_test_case(h2_encoder_data_stalled_completely)
add_test_case(h2_encoder_headers)
add_test_case(h2_encoder_priority)
add_test_case(h2_encoder_rst_stream)
add_test_case(h2_encoder_settings)
add_test_case(h2_encoder_settings_ack)
add_test_case(h2_encoder_push_promise)
add_test_case(h2_encoder_ping)
add_test_case(h2_encoder_goaway)
add_test_case(h2_encoder_window_update)

add_test_case(h2_decoder_sanity_check)
add_h2_decoder_test_set(h2_decoder_data)
add_h2_decoder_test_set(h2_decoder_data_padded)
add_h2_decoder_test_set(h2_decoder_data_pad_length_zero)
add_h2_decoder_test_set(h2_decoder_data_empty)
add_h2_decoder_test_set(h2_decoder_data_empty_padded)
add_h2_decoder_test_set(h2_decoder_data_ignores_unknown_flags)
add_h2_decoder_test_set(h2_decoder_data_payload_max_size_update)
add_h2_decoder_test_set(h2_decoder_err_data_payload_exceed_max_size)
add_h2_decoder_test_set(h2_decoder_err_data_requires_stream_id)
add_h2_decoder_test_set(h2_decoder_err_payload_too_small_for_pad_length)
add_h2_decoder_test_set(h2_decoder_stream_id_ignores_reserved_bit)
add_h2_decoder_test_set(h2_decoder_headers)
add_h2_decoder_test_set(h2_decoder_headers_padded)
add_h2_decoder_test_set(h2_decoder_headers_priority)
add_h2_decoder_test_set(h2_decoder_headers_ignores_unknown_flags)
add_h2_decoder_test_set(h2_decoder_headers_response_informational)
add_h2_decoder_test_set(h2_decoder_headers_request)
add_h2_decoder_test_set(h2_decoder_headers_cookies)
add_h2_decoder_test_set(h2_decoder_headers_trailer)
add_h2_decoder_test_set(h2_decoder_headers_empty_trailer)
add_h2_decoder_test_set(h2_decoder_err_headers_requires_stream_id)
add_h2_decoder_test_set(h2_decoder_err_headers_payload_too_small_for_padding)
add_h2_decoder_test_set(h2_decoder_err_headers_payload_too_small_for_priority)
add_h2_decoder_test_set(h2_decoder_malformed_headers_blank_name)
add_h2_decoder_test_set(h2_decoder_malformed_headers_illegal_name)
add_h2_decoder_test_set(h2_decoder_malformed_headers_response_to_server)
add_h2_decoder_test_set(h2_decoder_malformed_headers_request_to_client)
add_h2_decoder_test_set(h2_decoder_malformed_headers_mixed_pseudoheaders)
add_h2_decoder_test_set(h2_decoder_malformed_headers_late_pseudoheaders)
add_h2_decoder_test_set(h2_decoder_malformed_headers_trailer_must_end_stream)
add_h2_decoder_test_set(h2_decoder_malformed_header_continues_hpack_parsing)
add_h2_decoder_test_set(h2_decoder_continuation)
add_h2_decoder_test_set(h2_decoder_continuation_ignores_unknown_flags)
add_h2_decoder_test_set(h2_decoder_continuation_header_field_spans_frames)
add_h2_decoder_test_set(h2_decoder_continuation_many_frames)
add_h2_decoder_test_set(h2_decoder_continuation_empty_payloads)
add_h2_decoder_test_set(h2_decoder_err_continuation_frame_expected)
add_h2_decoder_test_set(h2_decoder_err_continuation_frame_same_stream_expected)
add_h2_decoder_test_set(h2_decoder_err_partial_header)
add_h2_decoder_test_set(h2_decoder_err_bad_hpack_data)
add_h2_decoder_test_set(h2_decoder_priority)
add_h2_decoder_test_set(h2_decoder_priority_ignores_unknown_flags)
add_h2_decoder_test_set(h2_decoder_err_priority_requires_stream_id)
add_h2_decoder_test_set(h2_decoder_err_priority_payload_too_small)
add_h2_decoder_test_set(h2_decoder_err_priority_payload_too_large)
add_h2_decoder_test_set(h2_decoder_rst_stream)
add_h2_decoder_test_set(h2_decoder_rst_stream_ignores_unknown_flags)
add_h2_decoder_test_set(h2_decoder_err_rst_stream_requires_stream_id)
add_h2_decoder_test_set(h2_decoder_err_rst_stream_payload_too_small)
add_h2_decoder_test_set(h2_decoder_err_rst_stream_payload_too_large)
add_h2_decoder_test_set(h2_decoder_settings)
add_h2_decoder_test_set(h2_decoder_settings_empty)
add_h2_decoder_test_set(h2_decoder_settings_ack)
add_h2_decoder_test_set(h2_decoder_settings_ignores_unknown_ids)
add_h2_decoder_test_set(h2_decoder_settings_ignores_unknown_flags)
add_h2_decoder_test_set(h2_decoder_err_settings_ack_with_data)
add_h2_decoder_test_set(h2_decoder_err_settings_forbids_stream_id)
add_h2_decoder_test_set(h2_decoder_err_settings_payload_size)
add_h2_decoder_test_set(h2_decoder_err_settings_invalid_values_enable_push)
add_h2_decoder_test_set(h2_decoder_err_settings_invalid_values_initial_window_size)
add_h2_decoder_test_set(h2_decoder_err_settings_invalid_values_max_frame_size)
add_h2_decoder_test_set(h2_decoder_push_promise)
add_h2_decoder_test_set(h2_decoder_push_promise_ignores_unknown_flags)
add_h2_decoder_test_set(h2_decoder_push_promise_continuation)
add_h2_decoder_test_set(h2_decoder_err_push_promise_continuation_expected)
add_h2_decoder_test_set(h2_decoder_err_push_promise_requires_stream_id)
add_h2_decoder_test_set(h2_decoder_err_push_promise_requires_promised_stream_id)
add_h2_decoder_test_set(h2_decoder_err_push_promise_with_enable_push_0)
add_h2_decoder_test_set(h2_decoder_malformed_push_promise_must_be_request_1)
add_h2_decoder_test_set(h2_decoder_malformed_push_promise_must_be_request_2)
add_h2_decoder_test_set(h2_decoder_ping)
add_h2_decoder_test_set(h2_decoder_ping_ack)
add_h2_decoder_test_set(h2_decoder_err_ping_forbids_stream_id)
add_h2_decoder_test_set(h2_decoder_err_ping_payload_too_small)
add_h2_decoder_test_set(h2_decoder_err_ping_payload_too_large)
add_h2_decoder_test_set(h2_decoder_goaway)
add_h2_decoder_test_set(h2_decoder_goaway_empty)
add_h2_decoder_test_set(h2_decoder_err_goaway_forbids_stream_id)
add_h2_decoder_test_set(h2_decoder_err_goaway_payload_too_small)
add_h2_decoder_test_set(h2_decoder_window_update_connection)
add_h2_decoder_test_set(h2_decoder_window_update_stream)
add_h2_decoder_test_set(h2_decoder_err_window_update_payload_too_small)
add_h2_decoder_test_set(h2_decoder_err_window_update_payload_too_large)
add_h2_decoder_test_set(h2_decoder_unknown_frame_type_ignored)
add_h2_decoder_test_set(h2_decoder_many_frames_in_a_row)
add_h2_decoder_test_set(h2_decoder_preface_from_server)
add_h2_decoder_test_set(h2_decoder_err_bad_preface_from_server_1)
add_h2_decoder_test_set(h2_decoder_err_bad_preface_from_server_2)
add_h2_decoder_test_set(h2_decoder_err_bad_preface_from_server_3)
add_h2_decoder_test_set(h2_decoder_preface_from_client)
add_h2_decoder_test_set(h2_decoder_err_bad_preface_from_client_1)
add_h2_decoder_test_set(h2_decoder_err_bad_preface_from_client_2)
add_h2_decoder_test_set(h2_decoder_err_bad_preface_from_client_3)

add_test_case(h2_client_sanity_check)
add_test_case(h2_client_stream_create)
add_test_case(h2_client_stream_release_after_complete)
add_test_case(h2_client_unactivated_stream_cleans_up)
add_test_case(h2_client_connection_preface_sent)
add_test_case(h2_client_auto_ping_ack)
add_test_case(h2_client_auto_ping_ack_higher_priority)

# TODO add_test_case(h2_client_auto_ping_ack_higher_priority_not_break_encoding_frame)
add_test_case(h2_client_auto_settings_ack)
add_test_case(h2_client_stream_complete)
add_test_case(h2_client_close)
add_test_case(h2_client_connection_init_settings_applied_after_ack_by_peer)
add_test_case(h2_client_stream_with_h1_request_message)
add_test_case(h2_client_stream_with_cookies_headers)
add_test_case(h2_client_stream_err_malformed_header)
add_test_case(h2_client_stream_err_state_forbids_frame)
add_test_case(h2_client_conn_err_stream_frames_received_for_idle_stream)
add_test_case(h2_client_stream_ignores_some_frames_received_soon_after_closing)
add_test_case(h2_client_conn_err_stream_frames_received_soon_after_closing)
add_test_case(h2_client_stream_err_stream_frames_received_soon_after_rst_stream_received)
add_test_case(h2_client_conn_err_stream_frames_received_after_removed_from_cache)
add_test_case(h2_client_stream_receive_info_headers)
add_test_case(h2_client_stream_err_receive_info_headers_after_main)
add_test_case(h2_client_stream_receive_trailing_headers)
add_test_case(h2_client_stream_err_receive_trailing_before_main)
add_test_case(h2_client_stream_receive_data)
add_test_case(h2_client_stream_err_receive_data_before_headers)
add_test_case(h2_client_stream_err_receive_data_not_match_content_length)
add_test_case(h2_client_stream_send_data)
add_test_case(h2_client_stream_send_lots_of_data)
add_test_case(h2_client_stream_send_stalled_data)
add_test_case(h2_client_stream_send_data_controlled_by_stream_window_size)
add_test_case(h2_client_stream_send_data_controlled_by_negative_stream_window_size)
add_test_case(h2_client_stream_send_data_controlled_by_connection_window_size)
add_test_case(h2_client_stream_send_data_controlled_by_connection_and_stream_window_size)
add_test_case(h2_client_stream_send_window_update)
add_test_case(h2_client_stream_send_window_update)
add_test_case(h2_client_stream_err_received_data_flow_control)
add_test_case(h2_client_conn_err_received_data_flow_control)
add_test_case(h2_client_conn_err_window_update_exceed_max)
add_test_case(h2_client_conn_err_window_update_size_zero)
add_test_case(h2_client_conn_err_initial_window_size_settings_cause_window_exceed_max)
add_test_case(h2_client_stream_receive_end_stream_before_done_sending)
add_test_case(h2_client_stream_receive_end_stream_and_rst_before_done_sending)
add_test_case(h2_client_stream_err_input_stream_failure)
add_test_case(h2_client_stream_err_receive_rst_stream)
add_test_case(h2_client_push_promise_automatically_rejected)
add_test_case(h2_client_conn_receive_goaway)
add_test_case(h2_client_conn_receive_goaway_debug_data)
add_test_case(h2_client_conn_err_invalid_last_stream_id_goaway)

# TODO add_test_case(h2_client_send_goaway_with_push_promises) id of 1st should be in GOAWAY 2nd should be ignored
add_test_case(h2_client_change_settings_succeed)
add_test_case(h2_client_change_settings_failed_no_ack_received)
add_test_case(h2_client_manual_window_management_disabled_auto_window_update)
add_test_case(h2_client_manual_window_management_user_send_stream_window_update)
add_test_case(h2_client_manual_window_management_user_send_stream_window_update_with_padding)
add_test_case(h2_client_manual_window_management_user_send_stream_window_update_overflow)
add_test_case(h2_client_manual_window_management_user_send_conn_window_update)
add_test_case(h2_client_manual_window_management_user_send_conn_window_update_with_padding)
add_test_case(h2_client_manual_window_management_user_send_connection_window_update_overflow)

# Build these when we address window_update() differences in H1 vs H2
# TODO add_test_case(h2_client_manual_updated_window_ignored_when_automatical_on)
# TODO add_test_case(h2_client_manual_stream_updated_window_ignored_invalid_state)
# TODO add_test_case(h2_client_manual_window_management_window_overflow) #we cannot ensure the increment_size is safe or not, let our peer detect the maximum exceed or not. But we can test the obviously overflows here.
add_test_case(h2_client_send_ping_successfully_receive_ack)
add_test_case(h2_client_send_ping_no_ack_received)
add_test_case(h2_client_conn_err_extraneous_ping_ack_received)
add_test_case(h2_client_conn_err_mismatched_ping_ack_received)
add_test_case(h2_client_empty_initial_settings)
add_test_case(h2_client_conn_failed_initial_settings_completed_not_invoked)
add_test_case(h2_client_stream_reset_stream)
add_test_case(h2_client_stream_reset_ignored_stream_closed)
add_test_case(h2_client_stream_reset_failed_before_activate_called)
add_test_case(h2_client_stream_keeps_alive_for_cross_thread_task)
add_test_case(h2_client_stream_get_received_reset_error_code)
add_test_case(h2_client_stream_get_sent_reset_error_code)
add_test_case(h2_client_new_request_allowed)
add_test_case(h2_client_send_multiple_goaway)
add_test_case(h2_client_get_sent_goaway)
add_test_case(h2_client_get_received_goaway)
add_test_case(h2_client_request_apis_failed_after_connection_begin_shutdown)
add_test_case(h2_client_get_local_settings)
add_test_case(h2_client_get_remote_settings)
add_test_case(h2_client_error_from_outgoing_body_callback_reset_stream)
add_test_case(h2_client_error_from_incoming_headers_callback_reset_stream)
add_test_case(h2_client_error_from_incoming_headers_done_callback_reset_stream)
add_test_case(h2_client_error_from_incoming_body_callback_reset_stream)
add_test_case(h2_client_manual_data_write)
add_test_case(h2_client_manual_data_write_not_enabled)
add_test_case(h2_client_manual_data_write_with_body)
add_test_case(h2_client_manual_data_write_no_data)
add_test_case(h2_client_manual_data_write_connection_close)

add_test_case(server_new_destroy)
add_test_case(connection_setup_shutdown)
add_test_case(connection_setup_shutdown_tls)
add_test_case(connection_setup_shutdown_proxy_setting_on_ev_not_found)
add_test_case(connection_setup_shutdown_pinned_event_loop)
add_test_case(connection_h2_prior_knowledge)
add_test_case(connection_h2_prior_knowledge_not_work_with_tls)
add_test_case(connection_customized_alpn)
add_test_case(connection_customized_alpn_error_with_unknown_return_string)

# These server tests occasionally fail. Resurrect if/when we get back to work on HTTP server.
# add_test_case(connection_destroy_server_with_connection_existing)
# add_test_case(connection_destroy_server_with_multiple_connections_existing)
# add_test_case(connection_server_shutting_down_new_connection_setup_fail)

# connection manager tests
# unit tests where connections are mocked
add_net_test_case(test_connection_manager_setup_shutdown)
add_net_test_case(test_connection_manager_acquire_release_mix_synchronous)
add_net_test_case(test_connection_manager_connect_callback_failure)
add_net_test_case(test_connection_manager_connect_immediate_failure)
add_net_test_case(test_connection_manager_proxy_setup_shutdown)
add_net_test_case(test_connection_manager_idle_culling_single)
add_net_test_case(test_connection_manager_idle_culling_many)
add_net_test_case(test_connection_manager_idle_culling_mixture)
add_net_test_case(test_connection_manager_idle_culling_refcount)

# tests where we establish real connections
add_net_test_case(test_connection_manager_single_connection)
add_net_test_case(test_connection_manager_single_http2_connection)
add_net_test_case(test_connection_manager_single_http2_connection_failed)
add_net_test_case(test_connection_manager_single_http2_connection_with_settings)
add_net_test_case(test_connection_manager_many_connections)
add_net_test_case(test_connection_manager_many_http2_connections)
add_net_test_case(test_connection_manager_acquire_release)
add_net_test_case(test_connection_manager_close_and_release)
add_net_test_case(test_connection_manager_acquire_release_mix)

# Integration test that requires proxy envrionment in us-east-1 region.
# TODO: test the server name validation properly
if(ENABLE_PROXY_INTEGRATION_TESTS)
    add_net_test_case(connection_manager_proxy_integration_forwarding_proxy_no_auth)
    add_net_test_case(connection_manager_proxy_integration_forwarding_proxy_no_auth_env)
    add_net_test_case(connection_manager_proxy_integration_legacy_http_no_auth)
    add_net_test_case(connection_manager_proxy_integration_legacy_http_no_auth_env)
    add_net_test_case(connection_manager_proxy_integration_legacy_https_no_auth)
    add_net_test_case(connection_manager_proxy_integration_legacy_https_no_auth_env)
    add_net_test_case(connection_manager_proxy_integration_tunneling_proxy_http_no_auth_env)
    add_net_test_case(connection_manager_proxy_integration_tunneling_proxy_https_no_auth)
    add_net_test_case(connection_manager_proxy_integration_tunneling_proxy_https_no_auth_env)
    add_net_test_case(connection_manager_proxy_integration_tunneling_proxy_double_tls_no_auth)
    add_net_test_case(connection_manager_proxy_integration_tunneling_proxy_double_tls_no_auth_env)
    add_net_test_case(connection_manager_proxy_integration_tunneling_proxy_double_tls_no_auth_configured_tls_env)
    add_net_test_case(connection_manager_proxy_integration_forwarding_proxy_basic_auth)
    add_net_test_case(connection_manager_proxy_integration_forwarding_proxy_basic_auth_env)
    add_net_test_case(connection_manager_proxy_integration_legacy_http_basic_auth)
    add_net_test_case(connection_manager_proxy_integration_legacy_http_basic_auth_env)
    add_net_test_case(connection_manager_proxy_integration_legacy_https_basic_auth)
    add_net_test_case(connection_manager_proxy_integration_legacy_https_basic_auth_env)
    add_net_test_case(connection_manager_proxy_integration_tunneling_proxy_http_basic_auth_env)
    add_net_test_case(connection_manager_proxy_integration_tunneling_proxy_https_basic_auth)
    add_net_test_case(connection_manager_proxy_integration_tunneling_proxy_https_basic_auth_env)

    add_net_test_case(h1_proxy_h2_host_tunneling_double_tls_no_auth)
endif()

add_test_case(h1_server_sanity_check)
add_test_case(h1_server_receive_1line_request)
add_test_case(h1_server_receive_headers)
add_test_case(h1_server_receive_body)
add_test_case(h1_server_receive_1_request_from_multiple_io_messages)
add_test_case(h1_server_receive_multiple_requests_from_1_io_messages)
add_test_case(h1_server_receive_bad_request_shut_down_connection)
add_test_case(h1_server_receive_close_header_ends_connection)
add_test_case(h1_server_receive_close_header_more_requests_illegal)

add_test_case(h1_server_send_1line_response)
add_test_case(h1_server_send_response_headers)
add_test_case(h1_server_send_response_body)
add_test_case(h1_server_send_response_to_HEAD_request)
add_test_case(h1_server_send_304_response)
add_test_case(h1_server_send_multiple_responses_in_order)
add_test_case(h1_server_send_multiple_responses_out_of_order)
add_test_case(h1_server_send_multiple_responses_out_of_order_only_one_sent)
add_test_case(h1_server_send_response_before_request_finished)
add_test_case(h1_server_send_response_large_body)
add_test_case(h1_server_send_response_large_head)
add_test_case(h1_server_send_close_header_ends_connection)
add_test_case(h1_server_send_close_header_with_pipelining)

add_test_case(h1_server_close_before_message_is_sent)
add_test_case(h1_server_error_from_incoming_request_callback_stops_decoder)
add_test_case(h1_server_error_from_incoming_headers_callback_stops_decoder)
add_test_case(h1_server_error_from_incoming_headers_done_callback_stops_decoder)
add_test_case(h1_server_error_from_incoming_request_done_callback_stops_decoder)
add_test_case(h1_server_error_from_incoming_body_callback_stops_decoder)
add_test_case(h1_server_error_from_outgoing_body_callback_stops_sending)
add_test_case(h1_server_close_from_off_thread_makes_not_open)
add_test_case(h1_server_close_from_on_thread_makes_not_open)

add_test_case(test_http_forwarding_proxy_connection_proxy_target)
add_test_case(test_http_forwarding_proxy_connection_channel_failure)
add_test_case(test_http_forwarding_proxy_connection_connect_failure)
add_test_case(test_http_forwarding_proxy_request_transform)
add_test_case(test_http_forwarding_proxy_request_transform_basic_auth)
add_test_case(test_http_forwarding_proxy_request_transform_legacy_basic_auth)
add_test_case(test_http_proxy_request_transform_kerberos)
add_test_case(test_http_proxy_kerberos_token_failure)
add_test_case(test_http_proxy_kerberos_connect_failure)
add_test_case(test_http_proxy_adaptive_identity_success)
add_test_case(test_http_proxy_adaptive_kerberos_success)
add_test_case(test_http_proxy_adaptive_ntlm_success)
add_test_case(test_http_proxy_adaptive_failure)
add_test_case(test_http_forwarding_proxy_uri_rewrite)
add_test_case(test_http_forwarding_proxy_uri_rewrite_options_star)
add_test_case(test_http_tunnel_proxy_connection_success)
add_test_case(test_https_tunnel_proxy_connection_success)
add_test_case(test_http_tunnel_proxy_connection_failure_connect)
add_test_case(test_https_tunnel_proxy_connection_failure_connect)
add_test_case(test_https_tunnel_proxy_connection_failure_tls)

add_test_case(test_http_connection_monitor_options_is_valid)
add_test_case(test_http_connection_monitor_rw_above)
add_test_case(test_http_connection_monitor_r_above)
add_test_case(test_http_connection_monitor_w_above)
add_test_case(test_http_connection_monitor_write_then_read_above)
add_test_case(test_http_connection_monitor_below_but_undetectable)
add_test_case(test_http_connection_monitor_rw_below)
add_test_case(test_http_connection_monitor_below_then_above)
add_test_case(test_http_connection_monitor_failure_reset_when_empty)

add_test_case(test_http_connection_monitor_bytes_overflow)
add_test_case(test_http_connection_monitor_time_overflow)
add_test_case(test_http_connection_monitor_shutdown)

add_test_case(test_http_stats_trivial)
add_test_case(test_http_stats_basic_request)
add_test_case(test_http_stats_split_across_gather_boundary)
add_test_case(test_http_stats_pipelined)
add_test_case(test_http_stats_multiple_requests_with_gap)

# Tests that not make real connection but use TLS. So, still need to be marked as net test
add_net_test_case(h2_sm_sanity_check)
add_net_test_case(h2_sm_mock_connection)
add_net_test_case(h2_sm_mock_multiple_connections)
add_net_test_case(h2_sm_mock_bad_connection_acquired)
add_net_test_case(h2_sm_mock_connections_closed_before_request_made)
add_net_test_case(h2_sm_mock_max_concurrent_streams_remote)
add_net_test_case(h2_sm_mock_fetch_metric)
add_net_test_case(h2_sm_mock_complete_stream)
add_net_test_case(h2_sm_mock_ideal_num_streams)
add_net_test_case(h2_sm_mock_large_ideal_num_streams)
add_net_test_case(h2_sm_mock_goaway)
add_net_test_case(h2_sm_connection_ping)

# Tests against real world server
add_net_test_case(h2_sm_acquire_stream)
add_net_test_case(h2_sm_acquire_stream_multiple_connections)
add_net_test_case(h2_sm_closing_before_connection_acquired)
add_net_test_case(h2_sm_close_connection_on_server_error)

# Tests against local server
if(ENABLE_LOCALHOST_INTEGRATION_TESTS)
    # Tests should be named with localhost_integ_*
    add_net_test_case(localhost_integ_h2_sm_prior_knowledge)
    add_net_test_case(localhost_integ_h2_sm_acquire_stream_stress)
    add_net_test_case(localhost_integ_h2_sm_acquire_stream_stress_with_body)
    add_net_test_case(localhost_integ_h2_sm_connection_monitor_kill_slow_connection)
endif()

add_test_case(random_access_set_sanitize_test)
add_test_case(random_access_set_insert_test)
add_test_case(random_access_set_get_random_test)
add_test_case(random_access_set_exist_test)
add_test_case(random_access_set_remove_test)
add_test_case(random_access_set_owns_element_test)

set(TEST_BINARY_NAME ${PROJECT_NAME}-tests)

generate_test_driver(${TEST_BINARY_NAME})

file(GLOB FUZZ_TESTS "fuzz/*.c")
aws_add_fuzz_tests("${FUZZ_TESTS}" "" "")

# SSL certificates to use for testing.
add_custom_command(TARGET ${TEST_BINARY_NAME} PRE_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_directory
    ${CMAKE_CURRENT_SOURCE_DIR}/resources $<TARGET_FILE_DIR:${TEST_BINARY_NAME}>)
